package com.pan.hisystem.controller;


import com.pan.hisystem.pojo.Department;
import com.pan.hisystem.pojo.RespBean;
import com.pan.hisystem.service.IDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qingyang
 * @since 2022-03-13
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @ApiOperation(value = "获取全部部门")
    @GetMapping("/getDeps")
    public List<Department> getDeps(){
        return departmentService.list();
    }

    @ApiOperation(value = "添加科室")
    @PostMapping("/addDep")
    public RespBean addDep(@RequestBody Department department){
        if(departmentService.save(department)){
            return RespBean.success("添加成功!");
        }
        return RespBean.error("添加失败!");
    }

    @ApiOperation(value = "修改科室")
    @PutMapping("/updateDep")
    public RespBean updateDep(@RequestBody Department department){
        if(departmentService.updateById(department)){
            return RespBean.success("修改成功!");
        }
        return RespBean.error("修改失败!");
    }

    @ApiOperation(value = "删除科室")
    @DeleteMapping("/deleteDep/{id}")
    public RespBean deleteDep(@PathVariable Integer id){
        if(departmentService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
